package org.hxd.dept.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import org.hxd.pojo.Dept;
import org.hxd.units.PageModel;

public class DeptDaoSql {
    public String findDept(@Param("pageModel") PageModel pageModel, @Param("name") final String name){
        return new SQL(){
            {
                this.SELECT("id,name,remark");
                this.FROM("dept_inf");
                if(name != null && !"".equals(name)){
                    this.WHERE("name like '%' #{name} '%'");
                }
                this.LIMIT("#{pageModel.firstLimitParam},#{pageModel.pageSize}");
            }
        }.toString();
    }
    public String findDeptCount(@Param("dept") final Dept dept){
        return new SQL(){
            {
                this.SELECT("count(*)");
                this.FROM("dept_inf");
                if(dept != null && dept.getName() != null && !"".equals(dept.getName())){
                    this.WHERE("name like '%' #{dept.name} '%'");
                }
            }
        }.toString();
    }
    public String removeDept(@Param("ids") Integer[] ids){
        StringBuffer sql = new StringBuffer();
        sql.append("delete from dept_inf where id in (");
        for (Integer id : ids) {
            sql.append(id+",");
        }
        sql.deleteCharAt(sql.length()-1);
        sql.append(")");
        return sql.toString();
    }
}
